#include <string>
	using std::string;
#include <stdexcept>
	using std::runtime_error;
#include <map>
	using std::map;
#include <set>
	using std::set;

#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp>
	using boost::algorithm::replace_all;

#include "unique_file_name_with_replacement.h"

string unique_file_name_with_replacement(	string		 				new_file_name,
											const map<string, string>&	replacements,
											set<string>& 				used_file_names, 
											const string& 				file_name_description)
{
	// substitute
	BOOST_FOREACH(auto& replace_pair, replacements) 
		replace_all(new_file_name, replace_pair.first, replace_pair.second);

	//
	//	Make sure file name is new
	//
	if (used_file_names.count(new_file_name))
		throw std::runtime_error("File name [" + new_file_name +"] " + file_name_description + " has been used before.");
	used_file_names.insert(new_file_name);

	return 	new_file_name;
}



